package com.pay.demo.service;

import com.pay.demo.common.util.SpringContextUtil;
import com.pay.demo.model.APayModel;
import com.pay.demo.model.BPayModel;
import com.pay.demo.model.base.PayModel;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * @program: demo
 * @description: 支付工厂Service
 * @author: guoxh
 * @create: 2019-04-01 15:30
 **/
@Service
public class PayFactoryService {

    /**
     * 支付通道路由
     *
     * @param channel
     * @return
     */
    public PayModel payChannelRoute(Integer channel) {
        if (channel == 1)
            return SpringContextUtil.getBean("aPayModel", APayModel.class);
        if (channel == 2)
            return SpringContextUtil.getBean("bPayModel", BPayModel.class);
        return null;
    }

    /**
     * 支付步骤处理
     *
     * @param payModel
     * @param payStep
     * @return
     */
    public ResponseEntity payStepProcess(PayModel payModel, String payStep) {
        if (payStep == null) {
            return new ResponseEntity("支付步骤为空", HttpStatus.BAD_REQUEST);
        }
        if (payStep.equalsIgnoreCase("CREATE_PAY_ORDER")) {
            payModel.createPayOrder();
        } else if (payStep.equalsIgnoreCase("SEND_PAY_SMS")) {
            payModel.sendPaySms();
        } else if (payStep.equalsIgnoreCase("PAY_CONFIRM")) {
            payModel.payConfirm();
        } else {
            return new ResponseEntity("错误的支付步骤", HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity(HttpStatus.OK);
    }
}
